﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Threading.Tasks;
using System;
using VOL.Entity.DomainModels;
using VOL.Smartmanufacturing;
using VOL.Smartmanufacturing.IServices.ProcessesProcedure;
using VOL.Core.Utilities;

namespace VOL.WebApi.Controllers.Smartmanufacturing
{
    /// <summary>
    /// 工艺与工序控制器Api-tsh
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class CraftController : ControllerBase
    {
        private readonly ICraftRouteServices _craftService;

        public CraftController(ICraftRouteServices craftService)
        {
            this._craftService = craftService;
        }

        /// <summary>
        /// 新增工艺路线
        /// </summary>
        /// <param name="craftRoute">实体</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public async Task<WebResponseContent> AddCraftRoute(CraftRoute craftRoute)
        {
            WebResponseContent webResponseContent  = new WebResponseContent();
            int i = await _craftService.AddCraftRoute(craftRoute);
            return i > 0 ? webResponseContent.OK("新增工艺路线成功",i) : webResponseContent.Error("新增工艺路线失败") ;
        }

        /// <summary>
        /// 修改工艺路线
        /// </summary>
        /// <param name="craftRoute">实体</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public async Task<WebResponseContent> UpdateCraftRoute(CraftRoute craftRoute)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            int i = await  _craftService.UpdateCraftRoute(craftRoute);
            return i > 0 ? webResponseContent.OK("修改工艺路线成功",i) : webResponseContent.Error("修改工艺路线失败");
        }

        /// <summary>
        /// 删除工艺路线
        /// </summary>
        /// <param name="id">主键编号</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public async Task<WebResponseContent> DeleteCraftRoute(int id)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            int i = await _craftService.DeleteCraftRoute(id);
            return i > 0 ? webResponseContent.OK("删除成功",i) : webResponseContent.Error("删除失败");
        }

        /// <summary>
        /// 获取所有工艺路线信息
        /// </summary>
        /// <returns>集合</returns>
        [HttpGet]
        public WebResponseContent GetCraftRouteList(int pageIndex, int pageSize)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            var result = _craftService.GetCraftRouteList(pageIndex, pageSize);
            return webResponseContent.OK("获取所有工艺路线信息成功", result);
        }

        /// <summary>
        /// 获取所有工序管理信息
        /// </summary>
        /// <returns>集合</returns>
        [HttpGet]
        public WebResponseContent GetCraftManagementList()
        {
            WebResponseContent  webResponseContent = new WebResponseContent();
            var result = _craftService.GetCraftManagementList();
            return webResponseContent.OK("获取所有工序管理信息成功", result);
        }
    }
}
